<!--
 * @Author: 订单支付的去支付按钮
 * @Date: 2020-06-29 15:52:06
 * @LastEditTime: 2020-07-07 09:59:15
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \JK商城\jkshopping\src\pages\payment\order\components\mes\address\components\btn.vue
--> 
<template>
  <div class="btn">
    <div class="btn_pay" @click="goPay">
      <p>去付款</p>
    </div>
    <van-popup v-model="show" position="bottom" :style="{ height: '60%' }" class="clearFix">
      <van-icon name="cross" class="close_icon" size="30" @click="close" />
      <van-password-input
        :value="value"
        info="密码为 6 位数字"
        :focused="showKeyboard"
        @focus="showKeyboard = true"
      />
      <!-- 数字键盘 -->
      <van-number-keyboard
        :show="showKeyboard"
        @input="onInput"
        @delete="onDelete"
        @blur="showKeyboard = false"
      />
    </van-popup>
  </div>
</template>

<script>
export default {
  data() {
    return {
      value: "",
      show: false,
      showKeyboard: true
    };
  },
  methods: {
    //点击支付弹出密码框
    goPay() {
      this.show = true;
    },
    // 获取密码框的值
    onInput(key) {
      this.value = (this.value + key).slice(0, 6);
      if (this.value.length === 6) {
        this.show = false;
        this.$toast.success("支付成功");
        setTimeout(() => {
          this.$router.push("./success");
        },2000);
      }
    },
    //数字框的删除数字按键
    onDelete() {
      this.value = this.value.slice(0, this.value.length - 1);
    },
    close() {
      console.log(111);
      this.$dialog
        .confirm({
          message: "是否取消付款"
        })
        .then(() => {
          this.$router.push("/fail");
        })
        .catch(() => {
          this.show = true;
          this.showKeyboard = true;
        });
    }

    
  }
};
</script>

<style lang="scss" scoped>
.btn {
  /*去支付按钮样式*/
  .btn_pay {
    width: 95%;
    height: 40px;
    background-color: #fa0334b9;
    margin-top: 20px;
    position: absolute;
    left: 50%;
    transform: translate(-50%);

    /*按钮里文字样式*/
    p {
      color: #fff;
      text-align: center;
      line-height: 40px;
      font-size: 18px;
    }
  }
  .van-password-input__security {
    // margin-top: 60px;
  }
  /*关闭图标的样式*/
  .close_icon {
    float: right;
  }
}
</style>